<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>期初订单相关的期初订单记录</title>
<script type="text/javascript">
    var hxId;
    Ext.onReady(function () {
        var hxesForOpeningStockDS = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model:'OpeningStockModel',
            proxy:{
                type:'ajax',
                extraParams:{id:<%=params[:id]%>},
                url:'/opening_stock/getHxesById',
                reader:{
                    type:'json',
                    root:'root',
                    totalProperty:'totalProperty'// 数据集记录总数
                }
            },
            autoLoad:true
        });

        //生成出库Grid的CM
        var hxesForOpeningStockCM = Ext.create('Ext.grid.column.Column', [Ext.create('Ext.grid.RowNumberer'), {
            header:'DB',
            dataIndex:'id',
            width:50
        }, {
            header:'部门',
            dataIndex:'department_name',
            width:70
        }, {
            header:'编辑者',
            dataIndex:'employee_name',
            width:70
        }, {
            header:'总金额',
            dataIndex:'amount',
            align:'right',
            renderer:Ext.util.Format.numberRenderer('0,000.00'),
            width:75
        }, {
            header:'进项税',
            dataIndex:'value_added_tax',
            align:'right',
            renderer:Ext.util.Format.numberRenderer('0,000.00'),
            width:85
        }, {
            header:'总金额(含税)',
            dataIndex:'tax_amount',
            align:'right',
            renderer:Ext.util.Format.numberRenderer('0,000.00'),
            width:100
        }, {
            header:'描述',
            dataIndex:'description',
            width:230
        }, {
            header:'变更日期',
            dataIndex:'created_at',
            renderer:Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width:110
        }, {
            header:'修改日期',
            dataIndex:'updated_at',
            renderer:Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width:110
        }
        ]);
        //生成要订单的产品的Grid
        var hxesForOpeningStockGrid = Ext.create('Ext.grid.Panel', {
            title:'期初订单列表',
            store:hxesForOpeningStockDS,
            columns:[Ext.create('Ext.grid.RowNumberer'), {
                header:'DB',
                dataIndex:'id',
                width:50
            }, {
                header:'部门',
                dataIndex:'department_name',
                width:70
            }, {
                header:'编辑者',
                dataIndex:'employee_name',
                width:70
            }, {
                header:'总金额',
                dataIndex:'amount',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:75
            }, {
                header:'进项税',
                dataIndex:'value_added_tax',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:85
            }, {
                header:'总金额(含税)',
                dataIndex:'tax_amount',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:100
            }, {
                header:'描述',
                dataIndex:'description',
                width:230
            }, {
                header:'变更日期',
                dataIndex:'created_at',
                renderer:Ext.util.Format.dateRenderer('Y-m-d H:i'),
                width:110
            }, {
                header:'修改日期',
                dataIndex:'updated_at',
                renderer:Ext.util.Format.dateRenderer('Y-m-d H:i'),
                width:110
            }],
            loadMask:true,
            width:945,
            height:230,
            frame:true
        });

        hxesForOpeningStockGrid.on('itemdblclick', function (gridPanel, record, item, index, e, options) {
            hxId = hxesForOpeningStockDS.getAt(index).get('id');
            var openingStockNumber = hxesForOpeningStockDS.getAt(index).get('order_number');
            //hxesForOpeningStockDS.load();
            openingStockHxDetailDS.removeAll();
            openingStockHxDetailDS.load({params:{'id':hxId}});
            openingStockHxDetailGrid.setTitle("期初订单的历史详细信息");
        });

        //--------------------------期初订单详细，双击后可显示数据----------------
        var openingStockHxDetailDS = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model:'OpeningStockDetailModel',
            proxy:{
                type:'ajax',
                url:'/opening_stock/getHxDetailsByHxId',
                reader:{
                    type:'json',
                    root:'root',
                    totalProperty:'totalProperty'// 数据集记录总数
                }
            }
        });

        //生成要订单的产品的Grid
        var openingStockHxDetailGrid = Ext.create('Ext.grid.Panel', {
            title:'期初订单详细列表',
            store:openingStockHxDetailDS,
            columns:[Ext.create('Ext.grid.RowNumberer'), {
                header:'DB',
                dataIndex:'id',
                width:50
            }, {
                header:'产品名称',
                dataIndex:'product_name',
                width:210
            }, {
                header:'编号', dataIndex:'product_number', width:100
            }, {
                header:'规格',
                dataIndex:'product_spec',
                width:80
            }, {
                header:'数量',
                dataIndex:'quantity',
                align:'right',
                width:80
            }, {
                header:'单价',
                dataIndex:'unit_price',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:70
            }, {
                header:'总价',
                dataIndex:'amount',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:70
            }, {
                header:'进项税',
                dataIndex:'value_added_tax',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:85
            }, {
                header:'单价(含税)',
                dataIndex:'tax_price',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:80
            }, {
                header:'总价(含税)',
                dataIndex:'tax_amount',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:85
            }, {
                header:'套装或单品',
                dataIndex:'is_suit',
                width:70
            }, {
                header:'备注',
                dataIndex:'description',
                width:150
            }],
            loadMask:true,
            width:945,
            height:285,
            frame:true
        });
        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
            width:955,
            height:640,
            frame:false,
            layout:{type:'table', columns:1},
            items:[hxesForOpeningStockGrid, openingStockHxDetailGrid]
        });
        workbenchPanel.render("hx_for_opening_stock_workbench_panel");
    })
</script>
</head>
<body>
<div id="hx_for_opening_stock_workbench_panel"></div>
</body>
</html>